import { type App, ComponentPublicInstance, createApp } from "vue";
import AppComp from "./App.vue";
import router from "@/router/index.js";
import { createPinia } from "pinia";

import { message } from "@/utils/Element";

import "element-plus/dist/index.css";
import "@/styles/common.scss";
import "@/styles/preset.scss";

const app: App = createApp(AppComp);

app.config.errorHandler = (err: unknown, instance: ComponentPublicInstance | null, info: string) => {
  console.group("<<< errorHandler >>>");
  console.log("err: ", err);
  console.log("instance", instance);
  console.log("info: ", info);
  console.groupEnd();

  if (["development", "tauri"].includes(import.meta.env.MODE)) {
    message.error(`global error: ${err}`);
	}
};

app.config.warnHandler = (msg: unknown, instance: ComponentPublicInstance | null, info: string) => {
  console.group("<<< warnHandler >>>");
  console.log("msg: ", msg);
  console.log("instance", instance);
  console.log("info: ", info);
  console.groupEnd();

  if (["development", "tauri"].includes(import.meta.env.MODE)) {
    message.error(`global warning: ${msg}`);
	}
};


app
  .use(router)
  .use(createPinia())
  .mount("#app");
